#include <bits/stdc++.h>
#define int long long 
using namespace std;

const int maxn = 2e5+5;
int arr[maxn];
int n, k;
bool check(int v){
	int summ = 0;
	for (int i=1;i<=n;i++) {
		summ += (arr[i] <= v ? arr[i] : v);
	}
	return summ/k >= v;
}

void solve(){
	cin >> n >> k;
	for (int i=1;i<=n;i++) {
		cin >> arr[i];
	}
	int l = 0;
	int r = 2e14+1;
	while(l < r-1){
		int m = ((r-l)>>1) + l;
		if (check(m)) {
			l=m;
		} else {
			r=m;
		}
	}
	cout << l << '\n';
}


signed main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t;
	t=1;
	while(t--){
		//TODO
		solve();
	}
	return 0;
}
